We are going to test JavaScript compatibility in the
following pages, but making JavaScript work requires more than just
support for the language. There are many technologies (or APIs) that are
bundled with JavaScript, but they are optional and will not work on all
devices.1. Document Object Model
DOM is a set of conventions for manipulating, browsing,
and editing XML and HTML documents using a set of API conventions that
may be implemented in many languages. In fact, although many developers
think that DOM is a JavaScript thing, this is wrong. There are DOM APIs
for PHP, .NET, Java, and many other languages.
Even if you’ve never heard about DOM, odds are good that you’ve
used it. If you’ve used the well-known document.getElementById function, for example,
you were using DOM.
Today, DOM is a W3C specification. The most compatible versions
for web use are the DOM Level 2 Core specification (DOM2CORE) and the
subspecification DOM Level 2 HTML (DOM2HTML) for HTML and XHTML
documents.
With DOM, we can browse the XHTML document structure and make
changes and additions dynamically from JavaScript without refreshing the
page.
A mobile browser can be JavaScript-compatible but without DOM
functionality. There are also some browsers that allow us to browse the
document tree but not to modify it on the fly.
2. Ajax
Ajax, originally an acronym of Asynchronous
JavaScript and XML, is a technique that involves making
asynchronous server requests without refreshing the page, interrupting
the user’s activity, changing the browser’s history, or losing global
state variables.
Note:
Why did I say “originally an acronym”? Today the term Ajax is
used in a more general way to define interactive Web 2.0 applications
that use asynchronous requests to the server, but may or may not be
written in XML. I even hear a lot about Ajax in dynamic websites using
the jQuery UI, ExtJS, or other rich control libraries that don’t
actually make background requests to the server.
The magic behind Ajax is called XMLHttpRequest; it is a
native JavaScript object available in compatible devices that was based
on an ActiveX object created by Microsoft in Internet Explorer
5.0.
3. JSON
JavaScript Object Notation (best known as JSON) is a
lightweight data interchange format known to be compatible with almost
every language in common use. It is sometimes used in JavaScript as a
replacement for other transport formats, like XML.
JSON can be used in Ajax requests. We will talk about differences
in the mobile browsers’ implementations in a while.
4. HTML 5 APIs
With the upcoming HTML 5 standard, JavaScript will support
some new APIs for client scripting and document work. Mobile browsers
are already adopting some of these new APIs, even though the standard is
still in discussion.
Some of the APIs we are going to discuss in this article are those
for:
5. Platform Extensions
There are other extensions available for web applications
on some devices, and many other JavaScript APIs are supported in
installed applications . These JavaScript APIs
can include support for: